#define MAXQSIZE 100
typedef double QElemType;

typedef struct QNode{
	QElemType data;
	struct QNode *next;
}QNode,*QueuePtr;

typedef struct{
	QueuePtr front;
	QueuePtr rear;
}LinkQueue;

bool InitQueue(LinkQueue &Q){
	Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode)); 
	if(!Q.front) 
		exit(-1);
    Q.front->next=NULL;
    return true;
}

bool DestroyQueue (LinkQueue &Q){
   while(Q.front){
      Q.rear=Q.front->next;
      free(Q.front);
      Q.front=Q.rear;   
   }    
   return true;
}

bool QueueEmpty(LinkQueue Q){
    if(Q.front==Q.rear)
		return true;
	return false;
 }


int GetLength(LinkQueue Q){
	return (Q.rear-Q.front+MAXQSIZE)%MAXQSIZE;
}

bool EnQueue(LinkQueue &Q,QElemType e){
    QueuePtr p=(QueuePtr)malloc(sizeof(QNode));
    if(!p) 
		exit(-1);

    p->data=e; 
	p->next=NULL;
    Q.rear->next=p;
    Q.rear=p;
    return true;
}

bool DeQueue(LinkQueue &Q,QElemType &e){
   QueuePtr p=(QueuePtr)malloc(sizeof(QNode));
   if(Q.front==Q.rear)
	   return false;

   p=Q.front->next;
   e=p->data;
   Q.front->next=p->next;
   if(Q.rear==p) Q.rear=Q.front;
   delete p;
   return false;
}